package com.doubao.doubao.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.doubao.doubao.common.api.ApiResult;
import com.doubao.doubao.mapper.BmsLeaderUploadMapper;
import com.doubao.doubao.model.entity.BmsAffairs;
import com.doubao.doubao.model.entity.BmsPost;
import com.doubao.doubao.model.entity.BmsUpFile;
import com.doubao.doubao.model.entity.UmsUser;
import com.doubao.doubao.service.IBmsLeaderUploadservice;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

import static com.doubao.doubao.jwt.JwtUtil.USER_NAME;


@RestController
@RequestMapping("/LeaderFiles")
public class BmsLeaderUploadController extends BaseController {

    @Resource
    private IBmsLeaderUploadservice iBmsLeaderUploadservice;
    @Resource
    BmsLeaderUploadMapper bmsLeaderUploadMapper;



    @RequestMapping(value = "/getLeaderFiles", method = RequestMethod.GET)
    public ApiResult<?> findFiles(@RequestParam(value = "groupid", defaultValue = "1")String groupid){
        List<Map<String, Object>> FilesPage =  bmsLeaderUploadMapper.selectMaps(new LambdaQueryWrapper<BmsUpFile>().eq(BmsUpFile::getGroupId, groupid));
        return ApiResult.success(FilesPage);
    }


    @PostMapping("/addLeaderFiles")
    public ApiResult<BmsUpFile> addFiles(@RequestBody BmsUpFile bmsUpFile){
        iBmsLeaderUploadservice.save(bmsUpFile);
        return ApiResult.success(bmsUpFile);
    }

    @DeleteMapping("/delete/{id}")
    public ApiResult<?> delete(@PathVariable Long id){
        bmsLeaderUploadMapper.deleteById(id);
        return ApiResult.success();
    }

//    @DeleteMapping("/delete/{id}")
//    public ApiResult<String> delete(@RequestHeader(value = USER_NAME) String userName, @PathVariable("id") String id) {
//        UmsUser umsUser = umsUserService.getUserByUsername(userName);
//        BmsPost byId = iBmsPostService.getById(id);
//        Assert.notNull(byId, "来晚一步，话题已不存在");
//        Assert.isTrue(byId.getUserId().equals(umsUser.getId()), "你为什么可以删除别人的话题？？？");
//        iBmsPostService.removeById(id);
//        return ApiResult.success(null,"删除成功");
//    }





}
